import QtQuick 1.0
import "Article.js" as ArticleUtil
//XmlListModel {
//    id:articleContentModel
//    source: article_page.article_list_url
//    query: "/Response/Articles/Article"


//         XmlRole { name: "articleId"; query: "ArticleId/string()" }
//         XmlRole { name: "articleTitle"; query: "Title/string()" }
//         XmlRole { name: "articlePublishTime"; query: "PublishTime/string()" }
//         XmlRole { name: "articleContent"; query: "Content/string()" }
//         XmlRole { name: "articleImage"; query: "Img/string()" }
//         XmlRole { name: "replyCount"; query: "ReplyCount/string()" }

//}

ListModel{
    id: container

    Component.onCompleted: {
        loadArticleList();
    }

    function loadArticleList(){
        console.log("module is ready");
        var doc = new XMLHttpRequest();
        doc.onreadystatechange = function() {
            if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
            } else if (doc.readyState == XMLHttpRequest.DONE) {
                var a = doc.responseXML.documentElement;

                var numNum =a.childNodes[0].childNodes[0].childNodes[0].nodeValue;
                article_page.all_page_num=numNum;//总文章数

                //插入一条焦点的item
                if(article_page.currentTypeId=="0"){
                     container.append({"itemType":"focus","articleId":"","articleTitle":"","articlePublishTime":"","articleContent":"","articleImage":"","replyCount":""});
                 }

                for (var i = 2; i < a.childNodes[0].childNodes.length; ++i) {//节点<Articles>


                    if(a.childNodes[0].childNodes[i] !== null && a.childNodes[0].childNodes[i].childNodes.length > 1){ // 去掉text节点

                        var title =      a.childNodes[0].childNodes[i].childNodes[0].childNodes[0].nodeValue; //节点<Article>
                         var articleId =  a.childNodes[0].childNodes[i].childNodes[1].childNodes[0].nodeValue;
                        var publishTime =  a.childNodes[0].childNodes[i].childNodes[2].childNodes[0].nodeValue;
                        var img =  a.childNodes[0].childNodes[i].childNodes[3].childNodes[0].nodeValue;
                        var replyCount =  a.childNodes[0].childNodes[i].childNodes[4].childNodes[0].nodeValue;
                        var content = a.childNodes[0].childNodes[i].childNodes[5].childNodes[0].nodeValue;
                      //  console.log("content:"+content);
                        container.append({"itemType":"content","articleId":articleId,"articleTitle":title,"articlePublishTime":publishTime,"articleContent":content,"articleImage":img,"replyCount":replyCount});
                    }
                }
            }
        }

        doc.open("GET", article_page.article_list_url);
        doc.send();
    }
}
